ME 02 - Virtual Memory Management (1-May-95)

Q When I unlock memory with UnlockMemory, does it affect only the memory I locked with LockMemory, or does it affect the whole page (i.e., will UnlockMemory unlock other memory in the same page)?

A It affects the whole page, not just a smaller part of it. The Virtual Memory lock and hold functions not only lock or hold a page (or pages) of memory, they also increment an internal counter associated with those VM pages. The counter for a page of memory has to return to its initial value (i.e., the value the counter was when the page was in the unlocked/unheld state) before a page is finally unlocked or unheld. So, even if you allocate a little piece of memory and lock it, and the rest of your page is locked by another program, the other program's LockMemory and UnlockMemory calls won't affect your locks.

References:

Inside Macintosh:Memory Chapter 1, Introduction to Memory Management, page 20, Locking and Unlocking Relocatable Blocks.



Return to Memory
Return to Technical Q & A's
Return to Developer Services and Products